package com.cy.mall.service.order.impl;

import com.cy.mall.dao.mapper.order.OrderAuditRecordMapper;
import com.cy.mall.model.domain.order.OrderAuditRecord;
import com.cy.mall.model.enums.Process;
import com.cy.mall.model.enums.order.AuditResult;
import com.cy.mall.service.BaseService;
import com.cy.mall.service.order.OrderAuditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Description 订单ppj 流程 审核 service
 * @Author tanyilin
 * @Date 2019/3/31 15:51
 */
@Service
public class OrderAuditServiceImpl extends BaseService implements OrderAuditService {

    @Autowired
    private OrderAuditRecordMapper orderAuditRecordMapper;

    @Override
    public void addOrderAuditRecord(Long orderId, Process process, AuditResult auditResult, String remark) {

        OrderAuditRecord dbOrderAuditRecord = new OrderAuditRecord();
        dbOrderAuditRecord.setOrderId(orderId);
        dbOrderAuditRecord.setProcess(process);
        dbOrderAuditRecord.setResult(auditResult);
        dbOrderAuditRecord = orderAuditRecordMapper.selectOne(dbOrderAuditRecord);
        if(dbOrderAuditRecord == null) {
            Date time = new Date();
            OrderAuditRecord orderAuditRecord = new OrderAuditRecord();
            orderAuditRecord.setOrderId(orderId);
            orderAuditRecord.setProcess(process);
            orderAuditRecord.setResult(auditResult);
            orderAuditRecord.setRemark(remark);
            orderAuditRecord.setManagerId(0L);
            orderAuditRecord.setCreateTime(time);
            orderAuditRecord.setUpdateTime(time);
            orderAuditRecordMapper.insertSelective(orderAuditRecord);
        }

    }
}
